package com.heima.minioDemo;

import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.errors.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.FileInputStream;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

//@SpringBootApplication
public class MinioDemoApplication {
    public static void main(String[] args) throws ServerException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        String[] fileNames={"C:\\Users\\KZJ\\Desktop\\Web_disk_download_folder\\day02-app端文章查看，静态化freemarker,分布式文件系统minIO\\资料\\模板文件\\plugins\\css\\index.css",
                "C:\\Users\\KZJ\\Desktop\\Web_disk_download_folder\\day02-app端文章查看，静态化freemarker,分布式文件系统minIO\\资料\\模板文件\\plugins\\js\\index.js",
                "C:\\Users\\KZJ\\Desktop\\Web_disk_download_folder\\day02-app端文章查看，静态化freemarker,分布式文件系统minIO\\资料\\模板文件\\plugins\\js\\axios.min.js"};
        String[] uploadNames={"plugins/css/index.css","plugins/js/index.js","plugins/js/axios.min.js"};
//        SpringApplication.run(MinioDemoApplication.class,args);;
        for(int i=0;i<fileNames.length;i++)
        {
            String suffix=uploadNames[i].substring((uploadNames[i]).lastIndexOf(".")+1);
            FileInputStream fileInputStream=new FileInputStream(fileNames[i]);
            MinioClient minioClient=MinioClient.builder().credentials("minio","minio123").endpoint("http:192.168.88.130:9000").build();
            PutObjectArgs putObjectArgs=PutObjectArgs.builder()
                    .object(uploadNames[i])
                    .contentType("text/"+suffix)
                    .bucket("leadnews")
                    .stream(fileInputStream,fileInputStream.available(),-1)
                    .build();
            minioClient.putObject(putObjectArgs);
            System.out.println("http://192.168.88.130:9000/leadnews/"+uploadNames[i]);
        }

    }
}
